package main

import (
	"fmt"
	"os"

	"github.com/olekukonko/tablewriter"

	"lianxi_go/lianxi_1/roll"
	"lianxi_go/lianxi_1/people"
	"lianxi_go/lianxi_1/npcs"
	"lianxi_go/lianxi_1/service"
)

func main(){
	npcWield()
	tablePring()
	npcPrint()


	port := os.Getenv("PORT")

	if len(port) == 0 {
		port = "12138"
	}
	server := service.NewServer()
	server.Run(":"+port)
}

func npcWield(){
	fmt.Println(roll.DieRoll(4))
	fmt.Println("这个操蛋的世界！")

	fmt.Printf("Rolled a die of size %d, result: %d\n", 6, roll.DieRoll(6))
	res1, res2 := roll.TwoRoll(6, 10)
	fmt.Printf("Rolled a pair of dice (%d,%d), results: %d, %d\n", 6, 10, res1,res2)

	named, err := roll.ReturnsNamed("globule",42)
	fmt.Printf("Named params returned: '%s', %v\n",named,err)
	fmt.Println(roll.GetDieRolls())

	var rolls = roll.GetDieRolls()

	for index, rollFunc := range rolls{
		fmt.Printf("Die Roll Attempt #%d, result %d\n",index,rollFunc(10))
	}
	people.AddNonPlayerCharacter()
	//fmt.Println(people.AddNonPlayerCharacter())
	people.SwordWield()
}

//表格
func tablePring(){
	data := [][]string{
		[]string{"Alfred","15","10/20","(10.32,56.21,30.25)"},
		[]string{"Beelzebub","30","30/50","(1,1,1)"},
		[]string{"Hortense","21","80/80","(1,1,1)"},
		[]string{"Pokey","8","30/40","(1,1,1)"},
	}
	table := tablewriter.NewWriter(os.Stdout)
	table.SetHeader([]string{"NPC","Speed","Power","Location"})
	table.AppendBulk(data)
	table.Render()
}

//NPC
func npcPrint(){
	mob := npcs.NonPlayerCharacter{Name:"史莱姆王"}
	fmt.Println(mob)

	hortense := npcs.NonPlayerCharacter{
		Name:"史莱姆王后",
		Loc:npcs.Location{X:10.0, Y:10.0, Z:10.0},
	}
	fmt.Println(hortense)
	fmt.Printf("%s与%s相距%f米！\n",mob.Name,hortense.Name,mob.DistanceTo(hortense))
}